<?php

use yii\db\Schema;

class m130524_201442_init extends \yii\db\Migration
{
    public $user = 'nxh_user';
    public $category = 'nxh_category';
    public $location = 'nxh_location';

	public function up()
	{
		$tableOptions = null;
		if ($this->db->driverName === 'mysql') {
			$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
		}

		$this->createTable($this->user, [
			'id' => Schema::TYPE_PK,
			'username' => Schema::TYPE_STRING . ' NOT NULL',
			'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
			'password_hash' => Schema::TYPE_STRING . ' NOT NULL',
			'password_reset_token' => Schema::TYPE_STRING . '(32)',
			'email' => Schema::TYPE_STRING . ' NOT NULL',
            'first_name' => Schema::TYPE_STRING . ' NOT NULL',
            'last_name' => Schema::TYPE_STRING . ' NOT NULL',
			'role' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1',
			'status' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1',
			'create_time' => Schema::TYPE_INTEGER.' NOT NULL',
			'update_time' => Schema::TYPE_INTEGER.' NOT NULL',
            'del_flg' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0',
		], $tableOptions);

        $this->createTable($this->category, [
            'id' => Schema::TYPE_PK,
            'parent_id' => Schema::TYPE_INTEGER . ' NOT NULL',
            'category_name' => Schema::TYPE_STRING . ' NOT NULL',
            'status_flg' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 1',
            'create_time' => Schema::TYPE_INTEGER.' NOT NULL',
            'update_time' => Schema::TYPE_INTEGER.' NOT NULL',
            'del_flg' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0',
        ], $tableOptions);

        $this->createTable($this->location, [
            'id' => Schema::TYPE_PK,
            'category_id' => Schema::TYPE_INTEGER.' NOT NULL',
            'subcategory_id' => Schema::TYPE_INTEGER.' NOT NULL',
            'name' => Schema::TYPE_STRING . ' DEFAULT NULL',
            'description' => Schema::TYPE_TEXT . ' DEFAULT NULL',
            'address' => Schema::TYPE_STRING . ' DEFAULT NULL',
            'city' => Schema::TYPE_STRING . ' DEFAULT NULL',
            'phone' => Schema::TYPE_STRING . ' DEFAULT NULL',
            'mobile' => Schema::TYPE_STRING . ' DEFAULT NULL',
            'websitelink' => Schema::TYPE_STRING . ' DEFAULT NULL',
            'latitude' => Schema::TYPE_FLOAT . ' NOT NULL',
            'longitude' => Schema::TYPE_FLOAT . ' NOT NULL',
            'note' => Schema::TYPE_TEXT . ' DEFAULT NULL',
            'status_flg' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 0',
            'create_time' => Schema::TYPE_INTEGER.' NOT NULL',
            'update_time' => Schema::TYPE_INTEGER.' NOT NULL',
            'del_flg' => Schema::TYPE_SMALLINT.' NOT NULL DEFAULT 0',
        ], $tableOptions);

	}

	public function down()
	{
        return $this->dropTable($this->user);
        return $this->dropTable($this->category);
        return $this->dropTable($this->location);
	}
}
